<%@ page language="java" contentType="text/html; UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <base href="//${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<a href="test/ssm">测试</a><br/>
<button id="btn1">Test @RequestBody1</button><br/>
<button id="btn2">Test @RequestBody2</button><br/>
<button id="btn3">Test @RequestBody3</button><br/>

<script>
    $(function () {
        $('#btn1').click(function () {
            $.ajax({
                url: "test/requestBody1",
                type: 'POST',
                data: {
                    arr: [2, 5, 8]
                },
                success: function (res) {
                    console.log(res);
                },
                error: function (err) {
                    console.log(err);
                }
            });
        });

        $('#btn2').click(function () {
            $.ajax({
                url: "test/requestBody2",
                type: 'POST',
                data: {
                    "array[0]": 2,
                    "array[1]": 5,
                    "array[2]": 8
                },
                success: function (res) {
                    console.log(res);
                },
                error: function (err) {
                    console.log(err);
                }
            });
        });

        $('#btn3').click(function () {
            let arr = [2, 5, 8];
            let arrStr = JSON.stringify(arr);
            $.ajax({
                url: "test/requestBody3",
                type: 'POST',
                data: arrStr,
                contentType: "application/json;charset=UTF-8",
                success: function (res) {
                    console.log(res);
                },
                error: function (err) {
                    console.log(err);
                }
            });
        });
    });
</script>
</body>
</html>